#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <cassert>

const int N = 1.1e5 + 5;

int n, m, k, p, q;
std::vector<int> adj[N], bdj[N], cdj[N], idj[N];
std::vector<std::pair<int, int>> edges;
int anc[N][20], dep[N], dfn[N], dfncnt, siz[N], ind[N];
int stk[N], top;
int fa[N];
unsigned long long f[N][5], tmp[5];
int t[N];
bool vis[N];

inline int lowbit(int x) { return x & (-x); }

inline int LCA(int x, int y) {
	if(dep[x] < dep[y]) std::swap(x, y);
	for(int i = 19; i >= 0; --i) if(dep[anc[x][i]] >= dep[y]) x = anc[x][i];
	if(x == y) {
		return x;
	}
	for(int i = 19; i >= 0; --i) if(anc[x][i] != anc[y][i]) x = anc[x][i], y = anc[y][i];
	return anc[x][0];
}

inline void dfs1(int u) {
	dfn[u] = ++dfncnt;
	siz[u] = 1;
	for(int v : adj[u]) {
		dfs1(v);
		siz[u] += siz[v];
	}
}

inline void dfs2(int u, int fa) {
	if(vis[u]) {
		f[u][1] = dep[u] - dep[fa];
		return;
	}
	f[u][0] = 1;
	for(int v : cdj[u]) {
		dfs2(v, u);
		std::memcpy(tmp, f[u], sizeof tmp);
		std::memset(f[u], 0, sizeof f[u]);
		for(int i = 0; i <= k; ++i) for(int j = 1; j <= k - i; ++j) {
			f[u][i+j] += tmp[i] * f[v][j];
		}
	}
	f[u][1] += dep[u] - dep[fa];
}

void solve() {
	std::cin >> k >> p;
	std::vector<std::pair<int, int>> vect(p);
	for(auto& e : vect) std::cin >> e.second, e.first = dfn[e.second], vis[e.second] = 1;
	sort(vect.begin(), vect.end());
	if(k == 1) {
		int u = LCA(vect.front().second, vect.back().second);
		std::cout << dep[u] << "\n";
		for(auto e : vect) vis[e.second] = 0;
		return;
	}
	stk[top = 1] = 1;
	std::vector<int> nodes;
	nodes.push_back(1);
	dep[1] = 1;
	for(auto e : vect) {
		int u = e.second;
		int lca = LCA(u, stk[top]);
		//std::cerr << u << " " << lca << "\n";
		while(dep[stk[top - 1]] > dep[lca]) {
			cdj[stk[top - 1]].push_back(stk[top]);
			--top;
		}
		if(stk[top] != lca) {
			cdj[lca].push_back(stk[top]);
			--top;
		}
		if(stk[top] != lca) {
			stk[++top] = lca;
			nodes.push_back(lca);
		}
		if(stk[top] != u) {
			stk[++top] = u;
			nodes.push_back(u);
		}
	}
	for(int i = 1; i < top; ++i) cdj[stk[i]].push_back(stk[i + 1]);
	dfs2(1, 0);
	std::cout << f[1][k] << "\n";
	for(int u : nodes) {
		std::memset(f[u], 0, sizeof f[u]);
		cdj[u].clear();
		vis[u] = 0;
	}
}

const int M = 1.1e3 + 5;

int cnt[M], sizz[M];
bool vvis[M];

inline void dfss(int u) {
	vvis[u] = 1;
	++cnt[u];
	for(int v : idj[u]) if(!vvis[v]) dfss(v);
}

inline void dfs3(int u) {
	siz[u] = vis[u];
	for(int v : bdj[u]) dfs3(v), siz[u] += siz[v];
	memset(f[u], 0, sizeof f[u]);
	if(vis[u]) {
		if(siz[u] == cnt[u]) f[u][1] = 1;
		return;
	}
	f[u][0] = 1;
	for(int v : bdj[u]) {
		if(siz[v]) {
			std::memcpy(tmp, f[u], sizeof tmp);
			std::memset(f[u], 0, sizeof f[u]);
			for(int i = 0; i <= k; ++i) for(int j = 1; j <= k - i; ++j) {
				f[u][i+j] += tmp[i] * f[v][j];
			}
		}
	}
	if(siz[u] == cnt[u]) {
		++f[u][1];
	}
}

void solve2() {
	std::cin >> k >> p;
	for(int i = 1; i <= n; ++i) vis[i] = 0;
	std::vector<int> vect(p);
	for(int& x : vect) std::cin >> x, vis[x] = 1;
	memset(cnt, 0, sizeof cnt);
	for(int x : vect) {
		memset(vvis, 0, sizeof vvis);
		dfss(x);
	}
	dfs3(1);
	std::cout << f[1][k] << "\n";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);

	freopen("lodge.in", "r", stdin);
	freopen("lodge.out", "w", stdout);

	std::cin >> n >> m >> q;
	for(int i = 1; i <= m; ++i) {
		int u, v; std::cin >> u >> v;
		adj[u].push_back(v), ++ind[v];
		idj[v].push_back(u);
	}
	std::queue<int> que;
	que.push(1);
	dep[1] = 1;
	while(!que.empty()) {
		int u = que.front(); que.pop();
		if(u != 1) {
			assert(fa[u] != 0);
			bdj[fa[u]].push_back(u);
			anc[u][0] = fa[u];
			dep[u] = dep[fa[u]] + 1;
			for(int i = 1; i <= 19; ++i) anc[u][i] = anc[anc[u][i-1]][i-1];
		}
		for(int v : adj[u]) {
			fa[v] = (!fa[v]) ? u : LCA(u, fa[v]);
			if(--ind[v] == 0) que.push(v);
			else edges.emplace_back(u, v);
		}
	}
	dfs1(1);
	for(int i = 1; i <= q; ++i) {
		if(n > 1000 && q > 1000) solve();
		else solve2();
	}

	return 0;
}
